package com.math3d;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

/**
 * @Author: clm
 * @Date: 2018-10-29
 */

public class Mat4 {
    public float[] mMat4;
    public FloatBuffer mFloatBuffer;
    public Mat4(){
        mMat4 = new float[16];

        initFB();
        normalize();
    }
    public final void normalize(){
        MatrixUtil.normalize(mMat4);
        mFloatBuffer.clear();
    }
    public final FloatBuffer getFloatBuffer(){
        mFloatBuffer.put(mMat4);
        mFloatBuffer.position(0);
        return mFloatBuffer;
    }

    private void initFB() {
        mFloatBuffer = ByteBuffer.allocateDirect(mMat4.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
        mFloatBuffer.clear();
    }

    /**
     * 设置平移部分
     */
    public final void setTranslate(float translate[]){
        mMat4[3] = translate[0];
        mMat4[7] = translate[1];
        mMat4[11] = translate[2];
    }

    /**
     * 设置为目标矩阵
     * @param mat4
     */
    public final void setTo(Mat4 mat4){
        for(int i = 0;i < 16;i++){
            mMat4[i] = mat4.mMat4[i];
        }
    }
    public final void translate(float x, float y, float z){

    }

    public Mat4(float[] mat4) {
        mMat4 = mat4;
        initFB();
        normalize();
    }
}
